package com.notifier.notifier;

import com.notifier.event.ErrorEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 邮件通知器
 *
 * @author Amadeus
 * @date 2025/10/14
 */
@Slf4j
@Component
public class MailNotifier implements IErrorNotifier {
    
//    @Autowired
//    private NotifyService notifyService;

    @Override
    public void notify(ErrorEvent event) {
        try {
            // TODO 只在特殊环境发送邮件
            if (!isEnabled()) {
                log.debug("非寻租环境，跳过邮件通知");
                return;
            }

            // TODO 配置项
            String[] mailAccount = {"352654980@qq.com"};
            String subject = "错误告警 - " + event.getApplicationName();
            String content = event.getFullErrorMessage();

            //TODO 待完善
//            notifyService.notifyMailSync(mailAccount, subject, content);
            log.debug("邮件通知发送成功，应用：{}", event.getApplicationName());
        } catch (Exception e) {
            log.warn("邮件通知发送失败", e);
        }
    }
    
    @Override
    public String getName() {
        return "MailNotifier";
    }
    
    @Override
    public boolean isEnabled() {
        // 根据环境判断是否启用邮件通知
        return false;
    }
}

